package com.guanyong.admin.controllers.page;

/**
 * Created by mxk on 2017/5/26.
 */
import com.guanyong.admin.handle.GlobleData;
import com.guanyong.model.FilmInfoModel;
import com.guanyong.model.FilmModel;
import com.guanyong.model.VideoScoreModel;
import com.guanyong.services.FilmServices;
import com.guanyong.services.VideoScoreService;
import com.qiniu.util.Auth;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import java.util.*;


@Controller
@RequestMapping("/page/video")
public class VideoPage  extends baseController {//视频
    @RequestMapping({"/tv"})
    String tvList(HttpServletRequest request) {
        return "/video/tv";
    }


    @RequestMapping({"/comic"})
    String comicList(HttpServletRequest request) {
        return "/video/comic";
    }


    @RequestMapping({"/variety"})
    String variety(HttpServletRequest request) {
        return "/video/variety";
    }

    @RequestMapping({"/filmlist"})
    String film(HttpServletRequest request) {
        return "/video/film";
    }

    @RequestMapping({"/filmadd"})
    String filmadd(HttpServletRequest request) {
        return "/video/filmadd";
    }

    @RequestMapping({"/commentlist"})
    String commentlist(HttpServletRequest request) {
        return "/video/commentlist";
    }
    @RequestMapping({"/toploglist"})
    String toploglist(HttpServletRequest request) {
        return "/video/toploglist";
    }

    @RequestMapping({"/todaylist"})
    String todaylist(HttpServletRequest request) {
        return "/video/todaylist";
    }

    @Autowired
    FilmServices filmServices;
    @Autowired
    VideoScoreService videoScoreService;

    @Autowired
    GlobleData globleData;

    @RequestMapping({"/filmupdate"})
    String filmupdate(Model model, HttpServletRequest request) {
        String id=request.getParameter("fid");
        FilmModel filmModel=filmServices.GetFilmModelById(id);
        FilmInfoModel filmInfoModel=filmServices.GetFilmInfoModelById(id);
        VideoScoreModel videoScoreModel=
                videoScoreService.GetVideoScoreByObjectId(1,id);
        if (filmModel!=null && filmInfoModel!=null&& videoScoreModel!=null){
            model.addAttribute("film",filmModel);
            model.addAttribute("filminfo",filmInfoModel);
            model.addAttribute("videoscore",videoScoreModel);
            return "/video/filmupdate";
        }
        else{

            return "errorPage/500";
        }

    }

    @RequestMapping({"/qiniufileup"})
    String qiniuFileUP(Model model, HttpServletRequest request) {


        String bucket = "voideapp";

        Auth auth = Auth.create(globleData.QiNiu_Ak, globleData.Qiniu_SK);

        String upToken = auth.uploadToken(bucket);

        System.out.println(upToken);

        model.addAttribute("uptoken",upToken);

        return "video/filesUP";
    }
}
